#include "pch.h"
#include "CppUnitTest.h"
#include <tchar.h>
#include "WaitForTask.h"
#include <tchar.h>

using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace Windows::System::Threading;
using namespace concurrency;

namespace UnitTests
{
    TEST_CLASS(CPPRestAPITests)
    {
    public:
        TEST_METHOD(ShouldConvertReadibilityArticle)
        {
			auto read = ref new Readibility();
			auto async =  create_task(read->MakeReadableAsync("http://msdn.microsoft.com/en-us/library/windows/apps/hh770552"));

			auto t = create_task([async] () -> String^
			{
				return async.get();
			});


			try
			{
				bool success;
				WaitForTask(t, success, 500000);
				
				String^ result = t.get();
				Assert::IsTrue(success, _T("Operation timed-out."));
				Assert::IsNotNull(result);
			}
			catch(Exception^ ex)
			{
				Assert::Fail(ex->Message->Data());
			}
        }

	};
}